#!/usr/bin/env python

import os, sqlite3

def run():

	#make a copy of the sms.db and call it sms.vac.db
	os.system("scp notes.sqlite notes.vac.sqlite")
	
	#now vacuum the sms.vac.db
	os.system("sqlite3 notes.vac.sqlite vacuum")
	
	#get the string value of sms.db in 1.txt
	os.system("strings notes.sqlite>1.txt")	
	
	#get the string value of sms.vac.db in 2.txt
	os.system("strings notes.vac.sqlite>2.txt")
	
	


	#now get the actual diff values by grepping the difference in the files
	os.system("grep -F -x -v -f 2.txt 1.txt > 3.txt")


	removeLines('CREATE')
	#	removeLines('35')
	removeLines('index')
	removeLines('DELETE')
	removeLines('WHERE')
	removeLines('AB')
	removeLines('NULL')
	removeLines('INSERT')
	removeLines('NEW')
	removeLines('OLD')
	removeLines('Type')
	removeLines('number')
	removeLines('table')
	removeLines('QQ')
	removeLines('WW')
	removeLines('QS')
	removeLines('NSStore')
	removeLinesWithFirstChar('35')
	removeEmptyLines()


	os.system('cat 3.txt')

	#now delete all the files that were created
	os.system("rm 1.txt")
	os.system("rm 2.txt")
	os.system("rm 3.txt")
	os.system("rm notes.vac.sqlite")

#removes lines that have the particular string
def removeLines(s):
	os.system("sed '/{}/d' 3.txt>temp.txt".format(s))
	os.system("mv temp.txt 3.txt")

def removeLinesWithFirstChar(s):
	os.system("sed '/^{}/ d' 3.txt>temp.txt".format(s))
	os.system("mv temp.txt 3.txt")

def removeEmptyLines():
	os.system('grep . 3.txt')
	# os.system("sed '/^$/d' 3.txt > tt")
	# os.system('mv tt 3.txt')

def main():
	#execute the run function
	run()

if __name__ == '__main__':
	main()